﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.WorkflowObjects;

namespace FRL.DebtChased.WorkflowEditor.WorkflowItemEditors
{

	/// <summary>
	/// Declaration of SearchCtrl class
	/// Controls for editing the workflow action to perform a search
	/// </summary>
	public partial class SearchCtrl : ActionBaseCtrl
	{

		/////////////////////////////////////////////////////////////
		// Construction

		public SearchCtrl()
		{

			// Initialize resources
			InitializeComponent();

		}

		/////////////////////////////////////////////////////////////
		// Implementation

		public override List<string> Validate()
		{

			// Declare return variable
			List<string> Ftmp = null;

			// Check controls
			if (txtMessageForCollector.Text.Length == 0)
			{
				if (Ftmp == null)
					Ftmp = new List<string>();
				Ftmp.Add("Enter a message for the account.");
			}			

			// Return variable
			return Ftmp;

		}

		public override void UpdateControls(WorkflowAction_Base action)
		{

			// Block update events
			this.BlockUpdateEvents = true;
			{

				// Cast the action
				WorkflowAction_Search searchAction = action as WorkflowAction_Search;
#if DEBUG
				Debug.Assert(searchAction != null);
#endif // #if DEBUG

				// Set the controls - Priority
				ComboBoxObject.SelectByItemData(cboPriority, (int)searchAction.Priority);

				// Set controls - message
				txtMessageForCollector.Text = searchAction.MessageForCollector;

				// Set controls - method
				ComboBoxObject.SelectByItemData(cboMethod, (int)searchAction.Method);

			}
			this.BlockUpdateEvents = false;

		}

		public override void UpdateFromControls(ref WorkflowAction_Base action)
		{

			// If the action needs changing...
			if (!(action is WorkflowAction_Search))
				action = new WorkflowAction_Search();

			// Cast the action
			WorkflowAction_Search searchAction = action as WorkflowAction_Search;
#if DEBUG
			Debug.Assert(searchAction != null);
#endif // #if DEBUG

			// Update object - Priority
			searchAction.Priority = (WorkflowAction_Base.ePriority)(cboPriority.SelectedItem as ComboBoxObject).ItemData;

			// Update object - message
			searchAction.MessageForCollector = txtMessageForCollector.Text;

			// Update object - method
			searchAction.Method = (WorkflowAction_Search.eMethod)(cboMethod.SelectedItem as ComboBoxObject).ItemData;

		}

		public override void InitializeControls()
		{

			// Priority
			WorkflowAction_Base.LoadPriorityDropDown(cboPriority, WorkflowAction_Base.ePriority.Low);

			// Search
			cboMethod.Items.Add(new ComboBoxObject(WorkflowAction_Search.MethodToDescription(WorkflowAction_Search.eMethod.Google_Manual),(int)WorkflowAction_Search.eMethod.Google_Manual,null));
			cboMethod.Items.Add(new ComboBoxObject(WorkflowAction_Search.MethodToDescription(WorkflowAction_Search.eMethod.Google_Automatic), (int)WorkflowAction_Search.eMethod.Google_Automatic, null));
			cboMethod.Items.Add(new ComboBoxObject(WorkflowAction_Search.MethodToDescription(WorkflowAction_Search.eMethod.CreditSearch_Manual), (int)WorkflowAction_Search.eMethod.CreditSearch_Manual, null));
			cboMethod.Items.Add(new ComboBoxObject(WorkflowAction_Search.MethodToDescription(WorkflowAction_Search.eMethod.CreditSearch_Automatic), (int)WorkflowAction_Search.eMethod.CreditSearch_Automatic, null));
			cboMethod.Items.Add(new ComboBoxObject(WorkflowAction_Search.MethodToDescription(WorkflowAction_Search.eMethod.Other), (int)WorkflowAction_Search.eMethod.Other, null));
			ComboBoxObject.SelectByItemData( cboMethod, (int)WorkflowAction_Search.eMethod.Google_Manual );

			// unblock update events
#if DEBUG
			Debug.Assert(this.BlockUpdateEvents);
#endif // #if DEBUG
			this.BlockUpdateEvents = false;

			// setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Event handlers

		private new void ActionBaseCtrl_Loaded(object sender, RoutedEventArgs e)
		{

			// Call base-class function
			base.ActionBaseCtrl_Loaded(sender, e);

			// setup controls
			_setupControls();

		}

		private void cboPriority_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{

			// Shortcuts
			if (this.BlockUpdateEvents)
				return;

			// If this control is in a tabbed panel...
			if (m_pnlAddAction != null)
				m_pnlAddAction.UpdateFromCtrl(this);

		}

		private void cboMethod_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{

			// Shortcuts
			if (this.BlockUpdateEvents)
				return;

			// If this control is in a tabbed panel...
			if (m_pnlAddAction != null)
				m_pnlAddAction.UpdateFromCtrl(this);

		}

		private void txtMessageForCollector_TextChanged(object sender, TextChangedEventArgs e)
		{

			// Shortcuts
			if (this.BlockUpdateEvents)
				return;

			// If this control is in a tabbed panel...
			if (m_pnlAddAction != null)
				m_pnlAddAction.UpdateFromCtrl(this);

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setupControls()
		{

			// Enable/disable controls

			// Show/hide controls

			// Show/hide controls- Email Options

		}

	}

}

